<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta http-equiv="Content-Type" content="text/html" charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
<title></title>
<script type="text/javascript" src="http://lib.sinaapp.com/js/jquery/1.9.1/jquery-1.9.1.min.js"></script>
<link rel="stylesheet" href="http://lib.sinaapp.com/js/bootstrap/3.3.7/css/bootstrap.min.css">
<script type="text/javascript" src="http://lib.sinaapp.com/js/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script type="text/javascript" src="mock.js"></script>
<base target="_black">

</head>
<body>

<div class="container">
	<div class="row">
		<div class="col-sm-12 col-lg-6">
			<div class="panel panel-default">
				<div class="panel-heading">source</div>
				<div class="panel-body">
					<textarea class="form-control" rows="3" id="source"></textarea>
				</div>
				<div class="panel-footer">
					<button type="button" class="btn btn-default" id="randomTest">生成一个随机字符串测试</button>
				</div>
			</div>
		</div>
		<div class="col-sm-12 col-lg-6">
			<div class="panel panel-default">
				<div class="panel-heading">source</div>
				<div class="panel-body">
					<textarea class="form-control" rows="3" id="results"></textarea>
				</div>
				<div class="panel-footer">
					<select class="form-control" name="opt">
						<option value="0">简单去空格</option>
						<option value="1">深度空格</option>
						<option value="2">下划线</option>
						<option value="3">中连线</option>
						<option value="4" selected="selected">小驼峰</option>
						<option value="5">大驼峰</option>
					</select>
				</div>
			</div>
			
		</div><!--col-->
	</div><!--row-->
	<div class="row">
		<!-- <input type="radio" name="" value=""> -->
		<div class="col-sm-12 col-lg-6">
			<button type="button" class="btn btn-default" id="btn">转换</button>
		</div>
		
	</div><!--row-->
	
</body>
<script type="text/javascript">
var sourceDom = document.getElementById("source");
var resultsDom = document.getElementById("results");
function strFormat(str,opt){
	str = str.trim();
	var re = '';
	var def = {
		hump:0//驼峰【0:不用，1:小驼峰，2:大驼峰】
		,attachment:'-'
	}
	// str = str.replace(/\s+/g,"");
	function includes(str){
		const sp = [' ','-','_'];
		for(var i in str){
			var s = sp.indexOf(str[i])
			if( s > -1 ){
				return sp[s];
			};//指定的特殊字符，用于下一步分割；
		}
		return false;//没有指定字符则使用驼峰检测
	}//注意后面的比较要用全等以区别布尔值和空格。
	function isSplit(letter){
		var isLetter = letter.toLowerCase() !== letter.toUpperCase();//存在大小写
		var isUpp = letter.toUpperCase() == letter;//可能是大写
		var isLow = letter.toLowerCase() == letter;//可能是小写
		return isLetter && isUpp;
	}
	function str2arr(str){
		var sp = includes(str);
		if( sp === false ){
			if( def.hump === 1 ){}
			if( def.hump === 2 ){}
		}
		return str.split(sp);
	}
	var arr = str2arr(str);
	// for(var i in arr){
	// 	re += arr[i]
	// }
	return arr
}
document.getElementById("randomTest").addEventListener('click',function(){
	sourceDom.value = Mock.mock('@sentence(3, 5)')
})
document.getElementById("btn").addEventListener('click',function(){
	var str = sourceDom.value;
	// var o = document.getElementsByName("opt")[0].value;
	// console.log(o)
	// var opt = {};
	resultsDom.value = strFormat(str);
})


</script>

</html>
